<?php 
require_once ("Lib/HeadlessFijiMacroExecuter.php");
//require_once "GlobalsClass.php"; 
require_once "../GlobalsClass.php"; 

// <editor-fold defaultstate="collapsed" desc="Prepare images (stacks) for Fiji">
$debug = false;
// Get a new Strategy obj to handle calling the macro
$macExec = new HeadlessFijiMacroExecuter(/* debug: */ $debug);
/////////////////////////////////////////////////
/////// FITS MACRO  /////////////////////////////
$macExec->set_macro_name("CreateStack_Resample_from_FITS.ijm");
// Linux
if (GlobalsClass::getPlatform() == PlatformType::linux) {
  $src_img_path = GlobalsClass::getImagesPath() . "Samples/";
  $result_img_path = GlobalsClass::getImagesPath() . "Samples/";
}
// Windows
else if (GlobalsClass::getPlatform() == PlatformType::windows) {
  $src_img_path = GlobalsClass::getImagesPath() . "Samples\\";
  $result_img_path = GlobalsClass::getImagesPath() . "Samples\\";
}

$result_img_name = "stack_from_resampled_FITS.zip";
$FITS_stack_with_rel_path = GlobalsClass::getImgPathRelToApplet()
                            . "Samples/$result_img_name"; // used in html                                                        
$scale = 2;

$args_array = array(/* debug: */ $debug, $src_img_path, $result_img_path,
                     $result_img_name, $scale);

$args_str = $macExec->construct_macro_str($args_array, GlobalsClass::getMacroArgDelim());

$macExec->set_macro_arg_str($args_str);
$macExec->execute_macro(); // creates the stack
  
/////////////////////////////////////////////////
/////// RAW MACRO  //////////////////////////////
$macExec->set_macro_name("Convert_F32_to_Tiff.ijm");
// Linux
if (GlobalsClass::getPlatform() == PlatformType::linux) {
  $src_img_path = GlobalsClass::getImagesPath() . "Samples/";
  $result_img_path = GlobalsClass::getImagesPath() . "Samples/";
}
// Windows
else if (GlobalsClass::getPlatform() == PlatformType::windows) {
  $src_img_path = GlobalsClass::getImagesPath() . "Samples\\";
  $result_img_path = GlobalsClass::getImagesPath() . "Samples\\";
}
$result_img_name = "stack_from_converted_RAW.zip";

$RAW_stack_with_rel_path = GlobalsClass::getImgPathRelToApplet()
                           . "Samples/$result_img_name"; // used in html                                                        
$scale = 2; // 2 means scale to 1/2
$rawImgType = "32-bit Real";
$rawWidth = 560;
$rawHeight = 560;
//$rawWidth   = 1024;
//$rawHeight  = 768;
$rawOffset = 0;
$rawNumImgs = 1;
$rawGapBetweenImgs = 0;
///// CONSTRUCT THE RAW MACRO ARGUMENT ///
$args_array = array($debug, $src_img_path, $result_img_path, $result_img_name, $scale,
                    $rawImgType, $rawWidth, $rawHeight, $rawOffset,
                    $rawNumImgs, $rawGapBetweenImgs); // order of args matters!

$args_str = $macExec->construct_macro_str($args_array, GlobalsClass::getMacroArgDelim());
$macExec->set_macro_arg_str($args_str);
$macExec->execute_macro(); // creates the stack   // </editor-fold>
                    
?>

<?php print('<?xml version="1.0" encoding="ISO-8859-1" ?>'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Elfinder Demo</title>

<!--  JQuery (packaged with Elfinder) -->
<script src="Elfinder1.2/js/jquery-1.6.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="Elfinder1.2/js/jquery-ui-1.8.13.custom.min.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="Elfinder1.2/css/smoothness/jquery-ui-1.8.13.custom.css" type="text/css" media="screen" charset="utf-8" />

<!--  Elfinder1.2 -->
<!--  min version -->
<script src="Elfinder1.2/js/elfinder.min.js" type="text/javascript" charset="utf-8"></script>

<!--  full version
<script src="Elfinder1.2/js/elfinder.full.js" type="text/javascript" charset="utf-8"></script>
-->
<link rel="stylesheet" href="Elfinder1.2/css/elfinder.css" type="text/css" media="screen" charset="utf-8" />



<script type="text/javascript" charset="utf-8">
	$().ready(function() {
		$('#file_exp').elfinder({
			url : 'Elfinder1.2/connectors/php/connector.php',
			lang : 'en' //,
          // Trying next line to fix cookie issue when run on my Desktop on Localhost
          //rememberLastDir : false
		});

		$('#hideAppletBtn').click(function(event){
      //alert("JQuery noticed you clicked inside the applet_div!");
      //$('#applet').hide(fast, null);
      $('#applet').remove(null);
    });
	});
</script>

</head>
  <body>

	<h4>ImageJ embedded in the website:</h4> 
	<div id="applet_div"
			 style="width: 80%; height: 500px; 
            border-style: solid; border-width: 1px; border-color: gray;
            z-index: -100">

    		<applet 
            id="applet"
						style="border-style: solid; border-width: 1px; border-color: gray;"
            
						codebase="ImageJ/Applet_Self_Signed"
						code="ij.ImageJApplet.class" archive="ImageJA.jar"
            
						width="100%" height="100%" 
						security="all-permissions"> 
						
						<!--  ImageJA version "ij-1.45h.jar" new as of May 2011 
						      Note that we must use the ImageJA version, not plain ImageJ
						      to get the fully embedded version (embedded in the webpage).
						-->
			<!--  
			<param name="url1" value="../../Images/Desert.jpg" />
			-->
			<param name="url1" value=<?="\"$FITS_stack_with_rel_path\""?>/>
      <param name="url2" value=<?="\"$RAW_stack_with_rel_path\""?>/>
			<!--  		  
		  <param name="url2" value=<?="\"" . GlobalsClass::getImgPathRelToApplet() . "Samples/convertedF32_11.zip\""?>/>
		  -->
		  <param name="eval1" value='run("Brightness/Contrast..."); 
		                             run("Enhance Contrast", "saturated=0.35");
		                             run("Put Behind [tab]");
		                             run("Next Slice [>]");
		                             run("Enhance Contrast", "saturated=0.35");
		                             '/>  
		     
		</applet>
     		
  </div>
  <!--<form>-->
    <button id="hideAppletBtn" title="Hide Applet">Hide that darn applet</button>
	<!--</form>	-->
  
	<h4>Elfinder File Explorer:
    <span style="color: blue;">Note: FirePHP should be disabled when going live!</span>
  </h4>
	<div id="file_exp"
	     style="border-style: solid; border-width: 1px; border-color: darkslategray;">
	
	</div>	
	
</body>
</html>